#!/bin/bash

if [ $# -lt 1 ]; then
  echo "use $0 test or $0 dev"
fi


if [ ! $1 = "test" ]; then
    if [ ! $1 = "dev" ]; then
        echo "use $0 test or $0 dev"
    fi
fi

PROFILE=$1

TIP="***********************************************"
CUR_DIR=$(cd `dirname $0`; pwd)
BIN_DIR=${CUR_DIR}/script

SRC_CODE_DIR=${CUR_DIR}/code

PRJ_APPLET=ptr-applet-background
PRJ_OPERATION=ptr-operation
PRJ_LOGS=ptr-logs
PRJ_WORKBENCH_WEB=ptr-workbench-web
PRJ_OPERATION_WEB=ptr-operation-web

echo "01 ${TIP} mkdir"
sh ${BIN_DIR}/10-mkdir.sh ${CUR_DIR} ${PRJ_APPLET}
sh ${BIN_DIR}/10-mkdir.sh ${CUR_DIR} ${PRJ_OPERATION}
sh ${BIN_DIR}/10-mkdir.sh ${CUR_DIR} ${PRJ_LOGS}
sh ${BIN_DIR}/10-mkdir.sh ${CUR_DIR} ${PRJ_OPERATION_WEB}
sh ${BIN_DIR}/10-mkdir.sh ${CUR_DIR} ${PRJ_WORKBENCH_WEB}

APPLET_GIT=git@codeup.aliyun.com:ptr/china-unionpay/ptr-applet-background.git
OPERATION_GIT=git@codeup.aliyun.com:ptr/china-unionpay/ptr-operation.git
LOGS_GIT=git@codeup.aliyun.com:ptr/china-unionpay/ptr-logs.git
WORKBENCH_WEB_GIT=git@codeup.aliyun.com:ptr/china-unionpay/ptr-workbench-web.git
OPERATION_WEB_GIT=git@codeup.aliyun.com:ptr/china-unionpay/ptr-operation-web.git

echo "02 ${TIP} pull code"

echo "CUR_DIR=${CUR_DIR}"
sh ${BIN_DIR}/20-pull_code.sh ${CUR_DIR} ${PRJ_OPERATION} ${OPERATION_GIT} develop


echo "03 ${TIP} mvn install"
sh ${BIN_DIR}/31-mvn_package_operation.sh ${CUR_DIR} ${CUR_DIR}/code ${PRJ_OPERATION}

echo "04 ${TIP} start service"
APPLET_JAR_DIR=${CUR_DIR}/${PRJ_APPLET}
OPERATION_JAR_DIR=${CUR_DIR}/${PRJ_OPERATION}
LOG_JAR_DIR=${CUR_DIR}/${PRJ_LOGS}

sh ${OPERATION_JAR_DIR}/start.sh ${OPERATION_JAR_DIR} test ptr-operation 31512 172.16.1.215:31515 &

